package com.SouthernWall_404.AgeRight.Common.world.items;

import com.SouthernWall_404.AgeRight.Common.API.LockAPI.KeyInfo;
import com.SouthernWall_404.AgeRight.Common.AgeRight;
import com.SouthernWall_404.AgeRight.Common.Init.ModItems;
import net.minecraft.ChatFormatting;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class KeyItem extends ModNBTItem{



    public KeyItem(Properties p_41383_) {
        super(p_41383_);
    }

    public static ItemStack getKey(KeyInfo keyInfo)
    {
        ItemStack key=new ItemStack(ModItems.KEY.get());
        key.setCount(1);
        CompoundTag modPack=getOrCreateModPack(key);
        CompoundTag keyPack=keyInfo.getCompoundPack();

        modPack.put(KeyInfo.KEYPACK_TAG,keyPack);

        putModPack(key,modPack);


        return key;
    }

    @Override
    public void appendHoverText(ItemStack itemStack, @Nullable Level p_41422_, List<Component> tooltip, TooltipFlag p_41424_) {
        super.appendHoverText(itemStack, p_41422_, tooltip, p_41424_);

        KeyInfo storeKeyInfo=KeyInfo.getFromItem(itemStack);//客户端的nbt为空

        tooltip.add(Component.translatable("tooltip."+ AgeRight.MODID+".storekey_2")
                .withStyle(style -> style.withColor(ChatFormatting.GRAY)));
        tooltip.add(
                Component.translatable("tooltip."+AgeRight.MODID+".storekey_1",
                        storeKeyInfo.blockPos.getX(),
                        storeKeyInfo.blockPos.getY(),
                        storeKeyInfo.blockPos.getZ(),
                        I18n.get(storeKeyInfo.block_name)
                ).withStyle(ChatFormatting.GREEN));
    }
}
